package com.byxm.wlgw.control.hyzx;

import java.util.List;
import java.util.Map;

import com.byxm.wlgw.bean.ShxxBean;
import com.byxm.wlgw.bean.YhxxBean;
import com.byxm.wlgw.bean.Yhxx_glBean;
import com.byxm.wlgw.control.BaseAction;
import com.byxm.wlgw.service.ShxxService;
import com.opensymphony.xwork2.ActionContext;

public class ShxxAction extends BaseAction{
	private static final long serialVersionUID = 1L;
	//用户信息ID
	private String yhxxid="";
	//收获信息id
	private String shxxid="0";
	
	private Map<String, Object> session;
	//收货信息
	private List<ShxxBean> lstShxx;
	
	private YhxxBean yhxxBean;
	
	private boolean bflag;
	
	ShxxBean shxxBean=null;
	
	ShxxService shxxService= new ShxxService();
	/**
	 * 获取收获信息
	 * @return
	 */
     public String list(){
    	 session=ActionContext.getContext().getSession();
    	 if(session.get("yhxxSession")==null){
    		 return "index";
    	 }else{
        	 yhxxBean=(YhxxBean)session.get("yhxxSession");
        	 lstShxx=shxxService.getShxxByYhxxid(yhxxBean.getYhxxid());
        	 return "success_01";
    	 }
     }
     /**
      * 添加收货信息
      * @return
      */
     public String save(){
    	 session=ActionContext.getContext().getSession();
         if(shxxBean.getShxxid()==0){
        	 if(session.get("yhxxSession")==null){
        		 return "index";
        	 }else{
            	 try {
            		 ShxxService shxxService=new ShxxService();
            		 yhxxBean=(YhxxBean)session.get("yhxxSession");
            		 shxxBean.setYhxxid(yhxxBean.getYhxxid());
        			 shxxService.insertShxx(shxxBean);
        			
        		} catch (Exception e) {
        			e.printStackTrace();
        		}
        	 }
         }else{
        	 try {
				shxxService.updateShxx(shxxBean);//修改收货信息
			} catch (Exception e) {
				e.printStackTrace();
			}
			
         }
    	 return "success_02";
     }
     
     public String load(){
   
    	 session=ActionContext.getContext().getSession();
    	 String resultStr="";
    	 
    	 int iShxxid=Integer.parseInt(shxxid);
    	 if(iShxxid==0&&session.get("yhxxSession")!=null){
    		 shxxBean=new ShxxBean();
    		 resultStr="success_03";
    	 }
    	 if(iShxxid!=0&&session.get("yhxxSession")!=null){
    		 shxxBean=shxxService.getShxxBeanfromDB(iShxxid);
    		 YhxxBean yhxxBean=(YhxxBean)session.get("yhxxSession");
    		 if(shxxBean.getYhxxid()!=yhxxBean.getYhxxid()){
    			 resultStr="index";
    		 }else {
    			 resultStr="success_03";
			}
 		}
    	 return resultStr;
     }
     
     /**
      * 删除收货信息
      * @return
      */
     public String delete(){
    	    try {
				if(shxxService.deleteShxx(Integer.parseInt(shxxid))){
					 bflag=true;
				 }else{
					 bflag=false;
				 }
			} catch (Exception e) {
				e.printStackTrace();
			}
    	 return "json";
     }
     
     
	public List<ShxxBean> getLstShxx() {
		return lstShxx;
	}
	public void setLstShxx(List<ShxxBean> lstShxx) {
		this.lstShxx = lstShxx;
	}

	public String getYhxxid() {
		return yhxxid;
	}

	public void setYhxxid(String yhxxid) {
		this.yhxxid = yhxxid;
	}

	public Map<String, Object> getSession() {
		return session;
	}

	public void setSession(Map<String, Object> session) {
		this.session = session;
	}
	public ShxxBean getShxxBean() {
		return shxxBean;
	}
	public void setShxxBean(ShxxBean shxxBean) {
		this.shxxBean = shxxBean;
	}
	public boolean isBflag() {
		return bflag;
	}
	public void setBflag(boolean bflag) {
		this.bflag = bflag;
	}
	public YhxxBean getYhxxBean() {
		return yhxxBean;
	}
	public void setYhxxBean(YhxxBean yhxxBean) {
		this.yhxxBean = yhxxBean;
	}
	public String getShxxid() {
		return shxxid;
	}
	public void setShxxid(String shxxid) {
		this.shxxid = shxxid;
	}
     
	
}
